/**
* @file logging.h
* @author Jan Sliacky
* 
* Logging
*
* April 2009
*
* Copyright (c) 2009 by Jan Sliacky
* All rights reserved.
*/

#ifdef PARIXT8

#define COLOR_LOGING 1;

#define LOG_TRC(x)  x;
#define LOG_DBG(x)  x;
#define LOG_MSG(x)  x;
#define LOG_INFO(x) x;
#define LOG_ERR(x)  x;

#else

#define COLOR_LOGING 1;

char const* foreground[] = {
                               "31",
                               "32",
                               "33",
                               "34",
                               "35",
                               "36",
                               "37",
                               "38",
                               "39"
                           };

char const* background[] = {
                               "49",
                               "40",
                               "47",
                               "45",
                               "46",
                               "43",
                               "44",
                               "42",
                               "41"
                           };

char const* log_level_name[] = { "trc", "dbg", "msg", "inf", "err"
                               };

struct timeval tp;

#define DO_LOG(lvl, command) \
	if(input_cfg->logLevel <= lvl) { \
		gettimeofday(&tp, NULL); \
		printf("\E[%s;%sm [%s][%d][%ld%ld][%s] %s:%d:", foreground[myRank%9], background[myRank/8], log_level_name[lvl], myRank, tp.tv_sec%1000, tp.tv_usec, status_names[procStatus], __FUNCTION__, __LINE__); \
		command; \
		printf("\n\E[39;49m"); \
		fflush(stdout); \
	}

#define LOG_TRC(x)  DO_LOG(trace, x)
#define LOG_DBG(x)  DO_LOG(debug, x)
#define LOG_MSG(x)  DO_LOG(msg, x)
#define LOG_INFO(x) DO_LOG(info, x)
#define LOG_ERR(x)  DO_LOG(error, x)

#endif
